#pragma once

extern const UINT UM_CREATEDEVICE;

extern LPCTSTR MAINWND_CLASS_NAME;
LRESULT CALLBACK MainWnd_InitialWindowProc(HWND hWnd, UINT uMsg,
	WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK MainWnd_WindowProc(HWND hWnd, UINT uMsg,
	WPARAM wParam, LPARAM lParam);

class MainWnd {
	static const float NEAR_PLANE;
	static const float FAR_PLANE;
	LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg,
		WPARAM wParam, LPARAM lParam);

	CComPtr<IDirect3DDevice9> device;
	D3DPRESENT_PARAMETERS present;
	D3DDISPLAYMODE mode;

	IDirect3D9 *pD3D9;
	HWND hwnd;
	float scale;
	D3DXMATRIX projectionMx;

	void UpdateProjection();
public:
	static ATOM Register(HINSTANCE hInstance);

	MainWnd();
	void SetHWnd(HWND hWnd);
	BOOL OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct);
	void OnPaint(HWND hWnd);
	void OnSize(HWND hwnd, UINT state, int cx, int cy);
	void OnDestroy(HWND hWnd);

	BOOL OnCreateDevice(HWND hwnd);
	void OnMouseWheel(HWND hwnd, int xPos, int yPos, int zDelta, UINT fwKeys);

	void InitPresentationParameters();

	friend LRESULT CALLBACK MainWnd_WindowProc(HWND hWnd, UINT uMsg,
		WPARAM wParam, LPARAM lParam);
};